package pattern.singleton;

/**
* @desc  懒汉式
* @author kanggw
* @datetime 2018/8/13,上午9:26
*/
public class LazySingleton {

  private volatile static LazySingleton instance = null;

    private LazySingleton() {
        this.instance = new LazySingleton();
    }


  public static LazySingleton getInstance(){

      if (null == instance) {
          synchronized (LazySingleton.class){
              if (null == instance) {
                  instance = getInstance();
              }
          }
      }

        return instance;
  }

    public static void main(String[] args) {
        Integer a = 1;
        Integer b = 2;
        Integer c = 3;
        Integer d = 3;
        Integer e = 321;
        Integer f = 321;
        Long g = 3L;
        System.out.println(c == d);
        System.out.println(e == f);
        System.out.println(c == (a + b));
        System.out.println(c.equals(a + b));
        System.out.println(g == (a + b));
        System.out.println(g.equals(a + b));
    }

}
